﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace proyecto1_bases2
{
    public partial class admin : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["us"] == null) {
                Server.Transfer("index.aspx", true);
            }

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                Dbms datos = new Dbms(Session["us"].ToString(), Session["pass"].ToString());
                String name = FileUpload1.FileName;
                string[] lines = { "cd C:\\banca_p1bd2 \n", "sqlldr userid=josedb/jmga1987 control="+name+".ctl log="+name+".log" };

                System.IO.File.WriteAllLines(@"C:\banca_p1bd2\"+name+".bat", lines);

                FileUpload1.SaveAs(@"C:\banca_p1bd2\" + name);
                string[] lines2 = { "LOAD DATA ", "INFILE \"C:\\banca_p1bd2\\" + name + "\" ",
                                  "INTO  TABLE TRANS_TEMP ",
                                  "APPEND  ",
                                  "fields terminated by '|' TRAILING NULLCOLS( ",
                                  " financiera_origen,",
                                  " cuenta_origen,",
                                  " nombre_origen,",
                                  " operacion,",
                                  " financiera_destino,",
                                  " cuenta_destino,",
                                  " nombre_destino,",
                                  "  monto",
                                  " )"
                                  };

                System.IO.File.WriteAllLines(@"C:\banca_p1bd2\" + name + ".ctl", lines2);
                System.Diagnostics.Process.Start(@"C:\banca_p1bd2\" + name + ".bat");

                datos.executeprocedure("execute carga_transacciones");
                Label1.Text = "correcto";
            }
        }
    }
}